package com.taptech.doufu.bean;

import java.util.ArrayList;

import com.taptech.doufu.constant.Constant;

public class MyAccountOperation {
	
	private static ArrayList<Integer> mLikedCommentIds;
	private static ArrayList<Integer> mCollectArticleIds;
	private static ArrayList<Integer> mCareMediaIds;

	// Account
	
	
	public static void setAccount(MyAccount account) {
		Constant.myAccount = account;
	}
	
	public static void setVerified(boolean verified) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setVerified(verified);
	}
	
	public static boolean isVerified() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getVerified();
		}
		
		return false;
	}
	
	
	public static int getId() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getId();
		}
		
		return -1;
	}
	
	public static void setId(int id) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setId(id);
	}
	
	public static String getUser() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getUser();
		}
		
		return null;
	}
	
	public static void setUser(String user) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setUser(user);
	}
	
	public static String getPassword() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getPassword();
		}
		
		return null;
	}
	
	public static void setPassword(String password) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setPassword(password);
	}
	
	public static String getAvatar() {
		
		if (Constant.myAccount != null) {
			return Constant.myAccount.getAvatar();
		}
		
		return null;
	}
	
	public static void setAvatar(String avatar) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setAvatar(avatar);
	}
	
	public static String getNickname() {
		
		if (Constant.myAccount != null) {
			return Constant.myAccount.getNickname();
		}
		
		return null;
	}
	
	public static void setNickname(String nickname) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setNickname(nickname);
	}
	
	public static int getCareCount() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getCareCount();
		}
		
		return 0;
	}
	
	public static void setCareCount(int careCount) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setCareCount(careCount);
	}
	
	
	public static int getCollectCount() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getCollectCount();
		}
		
		return 0;
	}
	
	public static void setCollectCount(int collectCount) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setCollectCount(collectCount);
	}
	
	
	
	public static int getCommentCount() {
		if (Constant.myAccount != null) {
			return Constant.myAccount.getCommentCount();
		}
		
		return 0;
	}
	
	public static void setCommentCount(int commentCount) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		
		Constant.myAccount.setCommentCount(commentCount);
	}
	
	public static void setAllCounts(int[] counts) {
		if (Constant.myAccount == null) {
			Constant.myAccount = new MyAccount();
		}
		Constant.myAccount.setCareCount(counts[0]);
		Constant.myAccount.setCollectCount(counts[1]);
		Constant.myAccount.setCommentCount(counts[2]);
	}
	
	public static int[] getAllCounts() {
		if (Constant.myAccount == null) {
			return new int[]{0, 0, 0};
			
		}
		
		return new int[] {
				Constant.myAccount.getCollectCount(), 
				Constant.myAccount.getCareCount(), 
				Constant.myAccount.getCommentCount()};
	}
	
	// liked comment
	
	public static void setLikedCommentIdList(ArrayList<Integer> likedCommentIds) {
		
		if (!isVerified()) {
			return;
		}
		
		mLikedCommentIds = likedCommentIds;
	}
	
	public static ArrayList<Integer> getLikedCommentIdList() {
		if (!isVerified()) {
			return null;
		}
		
		return mLikedCommentIds;
	}
	
	public static void addLikedCommentId(int likedCommentId) {
		
		if (!isVerified()) {
			return;
		}
		
		if (mLikedCommentIds == null) {
			mLikedCommentIds = new ArrayList<Integer>();
		}
		
		if (!mLikedCommentIds.contains(likedCommentId)) {
			mLikedCommentIds.add(likedCommentId);
		}
		
	}
	
	public static void delLikedCommentId(int likedCommentId) {
		
		if (!isVerified()) {
			return;
		}
		
		if (mLikedCommentIds == null) {
			return;
		}
		
		for (int i = 0; i < mLikedCommentIds.size(); i++) {
			if (mLikedCommentIds.get(i) == likedCommentId) {
				mLikedCommentIds.remove(i);
				i--;
			}
		}
	}
	
	// collect article
	
	public static void setCollectArticleIdList(ArrayList<Integer> collectArticleIds) {
		
		if (!isVerified()) {
			return;
		}
		
		mCollectArticleIds = collectArticleIds;
	}
	
	public static ArrayList<Integer> getCollectArticleIdList() {
		
		if (!isVerified()) {
			return null;
		}
		
		return mCollectArticleIds;
	}
	
	
	public static void addCollectArticleId(int collectId) {
		
		if (!isVerified()) {
			return;
		}
		
		if (mCollectArticleIds == null) {
			mCollectArticleIds= new ArrayList<Integer>();
		}
		
		if (!mCollectArticleIds.contains(collectId)) {
			mCollectArticleIds.add(collectId);
		}
		
		
	}
	
	public static void delCollectArticleId(int collectId) {
		
		if (!isVerified()) {
			return;
		}
		
		if (mCollectArticleIds == null) {
			return;
		}
		
		for (int i = 0; i < mCollectArticleIds.size(); i++) {
			if (mCollectArticleIds.get(i) == collectId) {
				mCollectArticleIds.remove(i);
				i--;
			}
		}
	}
	
	
	// care media
	public static void setCareMediaIdList(ArrayList<Integer> careMediaIds) {
		
		if (!isVerified()) {
			return;
		}
		
		mCareMediaIds = careMediaIds;
	}
	
	public static ArrayList<Integer> getCareMediaIdList() {
		
		if (!isVerified()) {
			return null;
		}
		
		return mCareMediaIds;
	}
	
	public static void addCareMediaId(int mediaId) {
		
		if (!isVerified()) {
			return;
		}
		
		if (mCareMediaIds == null) {
			mCareMediaIds= new ArrayList<Integer>();
		}
		
		if (!mCareMediaIds.contains(mediaId)) {
			mCareMediaIds.add(mediaId);
		}
	}
	
	public static void delCareMediaId(int mediaId) {
		
		if (!isVerified()) {
			return;
		}
		
		if (mCareMediaIds == null) {
			return;
		}
		
		for (int i = 0; i < mCareMediaIds.size(); i++) {
			if (mCareMediaIds.get(i) == mediaId) {
				mCareMediaIds.remove(i);
				i--;
			}
		}
	}
	
	public static void clearUserInfo() {
		Constant.myAccount = null;
	}
	
	
	
}
